//
//  MSFinancialAdministrationController.m
//  觅尚
//
//  Created by No.8 on 2019/4/6.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSFinancialAdministrationController.h"
#import "MSFinancialAdministrayionCell.h"
#import "MSFinanciaActivateCardController.h"
#import "MSsettleAccountsModel.h"
#define pageSize 20

@interface MSFinancialAdministrationController ()<UITableViewDelegate,UITableViewDataSource,MSFinancialAdministrayionCellDelegate>
//通用导航栏
{
    CustomNavigationBar *naviagtionBar;
    NSInteger page;
    NSInteger count;
    
}
/** 表视图*/
@property(nonatomic,strong)UITableView *tableView;

/** 挂账总额*/
@property(nonatomic,strong)UILabel *totleCountLabel;

/** 数组*/
@property(nonatomic,strong)NSMutableArray *romRecordListArray;

/** 取反*/
@property(nonatomic,strong)UIButton *typeButton;

/** 遮盖层*/
@property(nonatomic,strong)UIView *backView;


/** 弹出View*/
@property(nonatomic,strong)UIView *showView;


/** 数组*/
@property(nonatomic,strong)NSMutableArray *preciousSaleInfoArray;

/** 更新时间*/
@property(nonatomic,strong)UILabel * updatetimeLabel;


/** 房间状态*/
@property(nonatomic,strong)UILabel * ConsumptionLabel;


/** 房间消费总金额*/
@property(nonatomic,strong)UILabel * ConsumptionStatisticsLabel;


/** 金额*/
@property(nonatomic,strong)UITextField *TotalConsumptionField;

/** 金额*/
@property(nonatomic,strong)UILabel * BackConsumptionStatisticsLabel;


/** 挂账*/
@property(nonatomic,strong)UITextField *AccountsTextField;

/** 微信*/
@property(nonatomic,strong)UITextField *WeChatTextField;


/** 刷卡*/
@property(nonatomic,strong)UITextField *PaybycardTextField;

/** 会员卡支付*/
@property(nonatomic,strong)UITextField *MembershipcardTextField;


/** 支付宝*/
@property(nonatomic,strong)UITextField *AlipayTitleTextField;


/** 现金*/
@property(nonatomic,strong)UITextField *CashTextField;


/** 房间收益*/
@property(nonatomic,strong)NSString *totalIncome;

/** 挂账id*/
@property(nonatomic,strong)NSString *Roomopenid;


/** 挂账金额*/
@property(nonatomic,strong)NSString *RoomMoney;

@end

@implementation MSFinancialAdministrationController

/** Nav实现 */
- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    self.view.backgroundColor = backgroundcolor;
    
    self.romRecordListArray = [NSMutableArray new];
    
    Prepare *header = [Prepare headerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiHeaderRefresh)];
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = YES;
    // 马上进入刷新状态
    self.tableView.mj_header = header;
    [self.tableView.mj_header beginRefreshing];
//     [self ReloadData];
}
- (void)MJChiBaoZiHeaderRefresh{
    page = 1;
    [self ReloadData];
}

- (void)MJChiBaoZiFootderRefresh{
    
    if (count / pageSize < page) {
        [MBManager showBriefAlert:@"没有更多数据了"];
    }else{
        page++;
    }
    [self FootderRefreshReloadData];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    [self CreatView];
    
    [self tableView];
    
    PrepareFooter *footder = [PrepareFooter footerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiFootderRefresh)];
    // 马上进入刷新状态
    self.tableView.mj_footer = footder;
}

- (void)ReloadData{
    
    [MBManager showLoading];
    NSDictionary * params = @{@"busId":[WYCAccountTool unarchivebelongBusid],@"page":@(page),@"pageSize":@(pageSize)};
    [HTTPRequest POST:MSgetRoomRecord params:params succeed:^(id responseObject) {
        WYCLog(@"------%@",responseObject);
        if (CodeStr) {
            self.totleCountLabel.text = [NSString stringWithFormat:@"挂账总额: ￥%@",responseObject[@"data"][@"roomRecordMoney"]];
            count = [responseObject[@"data"][@"count"] integerValue];
            [self.tableView.mj_header endRefreshing];
            [MBManager hideAlert];
            NSMutableArray *temporaryArray = [NSMutableArray new];
             temporaryArray = [MSsettleAccountsModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"romRecordList"]];
            self.romRecordListArray = temporaryArray;
        }else{
            [self.tableView.mj_header endRefreshing];
            [MBManager hideAlert];
            [MBManager showBriefAlert:responseObject[@"msg"]];
            page = [params[@"page"] integerValue];

        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [MBManager hideAlert];
        [MBManager showBriefAlert:Failed];
    }];
}

- (void)FootderRefreshReloadData{
    [MBManager showLoading];
    NSDictionary * params = @{@"busId":[WYCAccountTool unarchivebelongBusid],@"page":@(page),@"pageSize":@(pageSize)};
    [HTTPRequest POST:MSgetRoomRecord params:params succeed:^(id responseObject) {
        
        if (CodeStr) {
            self.totleCountLabel.text = [NSString stringWithFormat:@"挂账总额: ￥%@",responseObject[@"data"][@"roomRecordMoney"]];
            [self.tableView.mj_footer endRefreshing];
            [MBManager hideAlert];
            self.romRecordListArray = [MSsettleAccountsModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"romRecordList"]];
        }else{
            [self.tableView.mj_footer endRefreshing];
            [MBManager hideAlert];
            [MBManager showBriefAlert:responseObject[@"msg"]];
            page --;
            
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [self.tableView.mj_footer endRefreshing];
        [MBManager hideAlert];
        [MBManager showBriefAlert:Failed];
    }];
    
}
- (void)CreatView{
    
    UIView * HeaderView = [[UIView alloc] init];
    HeaderView.x = 0;
    HeaderView.x = 0;
    HeaderView.width = ScreenWidth;
    HeaderView.backgroundColor = backgroundcolor;
    
    //    self.CollectionHeaderView = HeaderView;
    
    /** 房间总量*/
    UILabel * totleCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(40 * px, 40 * px, ScreenWidth / 3 * 2, 60 * px)];
    totleCountLabel.textColor = [UIColor whiteColor];
    totleCountLabel.text = @"挂账总额     ￥1800";
    totleCountLabel.textAlignment = NSTextAlignmentLeft;
    totleCountLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [HeaderView addSubview:totleCountLabel];
    self.totleCountLabel = totleCountLabel;

    
    UIView * LineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(totleCountLabel.frame) + 30 * px, HeaderView.width, 1)];
    LineView.backgroundColor = BackViewColor;
    [HeaderView addSubview:LineView];
    
//
//    UITextField * seachField = [[UITextField alloc] initWithFrame:CGRectMake(totleCountLabel.x, CGRectGetMaxY(LineView.frame) + 20 * px, HeaderView.width - 80 * px, 120 * px)];
//    seachField.placeholder = @"搜索房间号";
//    seachField.layer.borderColor = [UIColor grayColor].CGColor;
//    seachField.layer.borderWidth = 1.0f;
//    seachField.layer.cornerRadius = 10 * px;
//    seachField.keyboardType = UIKeyboardTypeNumberPad;
//    [seachField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
//    [seachField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
//    seachField.textColor = [UIColor whiteColor];
//    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"搜索"]];
//    imgView.frame = CGRectMake(20 * px, 30 * px, 60 * px, 60 * px);
//    seachField.leftView = imgView;
//    seachField.leftViewMode = UITextFieldViewModeAlways;
//    [HeaderView addSubview:seachField];
    
    
    UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(LineView.frame) + 50 * px, HeaderView.width, 120 * px)];
    titleView.backgroundColor = BackViewColor;
    [HeaderView addSubview:titleView];
    NSArray * titleArray = @[@"日期",@"房间",@"订房人",@"金额",@"操作"];
    
    CGFloat CommoditytitleWidth = HeaderView.width / titleArray.count;
    CGFloat CommoditytitleY = 0;
    CGFloat CommoditytitleHeight = titleView.height;
    for (int index = 0; index < titleArray.count; index ++) {
        /** 标题label*/
        UILabel * Commoditytitle = [[UILabel alloc] init];
        Commoditytitle.x = CommoditytitleWidth * index;
        Commoditytitle.y = CommoditytitleY;
        Commoditytitle.width = CommoditytitleWidth;
        Commoditytitle.height = CommoditytitleHeight;
        Commoditytitle.textColor = WYCRGBColor(102, 121, 145);
        Commoditytitle.text = titleArray[index];
        Commoditytitle.textAlignment = NSTextAlignmentCenter;
        Commoditytitle.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
        [titleView addSubview:Commoditytitle];
    }
    
    HeaderView.height = CGRectGetMaxY(titleView.frame);
    [self.view addSubview:HeaderView];
    self.tableView.tableHeaderView = HeaderView;
}
/** 表视图*/
- (UITableView *)tableView{
    self.extendedLayoutIncludesOpaqueBars = YES;
    if (!_tableView) {
        
        if (@available(iOS 11.0, *)) {
            
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.romRecordListArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140 * px;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MSFinancialAdministrayionCell * cell = [MSFinancialAdministrayionCell cellWithTableView:tableView];
    tableView.backgroundColor = [UIColor clearColor];
    cell.operationButtonDelegate = self;
    [cell.operationButton addTarget:self action:@selector(operationButtonClick) forControlEvents:UIControlEventTouchUpInside];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.settleAccountsModel = self.romRecordListArray[indexPath.row];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    MSFinanciaActivateCardController * FinanciaActivateCardVC = [[MSFinanciaActivateCardController alloc] init];
//    [self.navigationController pushViewController:FinanciaActivateCardVC animated:NO];
}
- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"挂账管理";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)ClickRoomName:(NSString *)RoomName Roomopenid:(NSString *)Roomopenid
{
    WYCLog(@"RoomName-----%@",RoomName);
    self.RoomMoney = RoomName;
    self.Roomopenid = Roomopenid;
    
    
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}
- (void)operationButtonClick{
    //弹出
//    - (void)ConsumptionClick{
    
        WYCLogFunc;
        UIView * view = [[UIView alloc] init];
        view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [[UIApplication sharedApplication].keyWindow  addSubview:view];
        self.backView = view;
        UITapGestureRecognizer *tapGesturRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    
        [view addGestureRecognizer:tapGesturRecognizer];
        
        
        UIView * showView = [[UIView alloc] init];
        showView.frame = CGRectMake(0, ScreenHeight / 2, ScreenWidth , ScreenHeight / 2);
        showView.backgroundColor = [UIColor whiteColor];
        [view addSubview:showView];
        self.showView = showView;
        //设置所需的圆角位置以及大小
        UIBezierPath * showViewmaskPath = [UIBezierPath bezierPathWithRoundedRect:showView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
        CAShapeLayer * showViewmaskLayer = [[CAShapeLayer alloc] init];
        showViewmaskLayer.frame = showView.bounds;
        showViewmaskLayer.path = showViewmaskPath.CGPath;
        showView.layer.mask = showViewmaskLayer;
        
        UIButton * BackButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 50 * px, 10 * px, 100 * px, 20 * px)];
        [BackButton addTarget:self action:@selector(BackButtonClick) forControlEvents:UIControlEventTouchUpInside];
        BackButton.layer.cornerRadius = 5 * px;
        BackButton.backgroundColor = DividinglineColor;
        [showView addSubview:BackButton];
        
        
        /** 消费统计总额*/
        UILabel * BackConsumptionStatisticsTitle = [[UILabel alloc] initWithFrame:CGRectMake(60 * px, 80 * px, 300 * px, 60 * px)];
        BackConsumptionStatisticsTitle.textColor = [UIColor blackColor];
        BackConsumptionStatisticsTitle.text = @"消费统计总额";
        BackConsumptionStatisticsTitle.textAlignment = NSTextAlignmentLeft;
        BackConsumptionStatisticsTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        [showView addSubview:BackConsumptionStatisticsTitle];
        
        
        /** 消费统计总额*/
        UILabel * BackConsumptionStatisticsLabel = [[UILabel alloc] initWithFrame:CGRectMake(showView.width / 2, BackConsumptionStatisticsTitle.y, showView.width / 2 - 40 * px, BackConsumptionStatisticsTitle.height)];
        BackConsumptionStatisticsLabel.textColor = FontColor;
        BackConsumptionStatisticsLabel.text = [NSString stringWithFormat:@"￥%@",self.RoomMoney];
        BackConsumptionStatisticsLabel.textAlignment = NSTextAlignmentRight;
        BackConsumptionStatisticsLabel.font = BackConsumptionStatisticsTitle.font;
        [showView addSubview:BackConsumptionStatisticsLabel];
        
        UIView * ConsumptionLineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(BackConsumptionStatisticsLabel.frame) + 30 * px, showView.width, 1)];
        ConsumptionLineView.backgroundColor = DividinglineColor;
        [showView addSubview:ConsumptionLineView];
        self.BackConsumptionStatisticsLabel = BackConsumptionStatisticsLabel;
        
        
    
        
        
        /** 结算方式*/
        UILabel * SettlementMethodLabel = [[UILabel alloc] initWithFrame:CGRectMake(BackConsumptionStatisticsTitle.x, CGRectGetMaxY(ConsumptionLineView.frame) + 30 * px, 200 * px, BackConsumptionStatisticsTitle.height)];
        SettlementMethodLabel.textColor = BackConsumptionStatisticsTitle.textColor;
        SettlementMethodLabel.text = @"结算方式";
        SettlementMethodLabel.textAlignment = BackConsumptionStatisticsTitle.textAlignment;
        SettlementMethodLabel.font = BackConsumptionStatisticsTitle.font;
        [showView addSubview:SettlementMethodLabel];
        
        UIView * MethodView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(SettlementMethodLabel.frame) + 20 * px, SettlementMethodLabel.y, ConsumptionLineView.width - SettlementMethodLabel.x - SettlementMethodLabel.width - 60 * px, showView.height - SettlementMethodLabel.y - 200 * px)];
        MethodView.backgroundColor = [UIColor clearColor];
        [showView addSubview:MethodView];
        
        
        
        
        
        
        /****************微信 **************/
        /** 选中按钮*/
        UIButton * WeChatButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60 * px, 60 * px)];
        [WeChatButton  setImage:[UIImage imageNamed:@"筛选-未选中"] forState:UIControlStateNormal];
        [WeChatButton  setImage:[UIImage imageNamed:@"勾"] forState:UIControlStateSelected];
        [WeChatButton  addTarget:self action:@selector(WeChatButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [MethodView  addSubview:WeChatButton];
        
        
        /** 微信标题*/
        UILabel * WeChatTitle = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(WeChatButton.frame) + 30 * px, WeChatButton.y, 100 * px, WeChatButton.height)];
        WeChatTitle.textColor = [UIColor blackColor];
        WeChatTitle.text = @"微信";
        WeChatTitle.textAlignment = NSTextAlignmentLeft;
        WeChatTitle.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        [MethodView addSubview:WeChatTitle];
        
        
        UITextField * WeChatTextField = [[UITextField alloc] init];
        WeChatTextField.frame = CGRectMake(CGRectGetMaxX(WeChatTitle.frame) + 20 * px, WeChatButton.y, MethodView.width - WeChatButton.width - WeChatTitle.width - 120 * px, WeChatButton.height);
        //        WeChatTextField.placeholder = @"请输入手机号";
        
        [WeChatTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [WeChatTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        WeChatTextField.keyboardType = UIKeyboardTypeNumberPad;
        WeChatTextField.textColor = [UIColor blackColor];
        [MethodView addSubview:WeChatTextField];
        self.WeChatTextField = WeChatTextField;
        
        
        UIView *WeChatLine = [[UIView alloc] initWithFrame:CGRectMake(WeChatTextField.x, CGRectGetMaxY(WeChatTextField.frame), WeChatTextField.width, 1)];
        WeChatLine.backgroundColor = DividinglineColor;
        [MethodView addSubview:WeChatLine];
        
        
        /** 微信标题*/
        UILabel * WeChatYLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(WeChatLine.frame) + 20 * px, WeChatButton.y, 50 * px, WeChatButton.height)];
        WeChatYLabel.textColor = WeChatTitle.textColor;
        WeChatYLabel.text = @"元";
        WeChatYLabel.textAlignment = WeChatTitle.textAlignment;
        WeChatYLabel.font = WeChatTitle.font;
        [MethodView addSubview:WeChatYLabel];
        
        
        
        
        /****************刷卡Paybycard**************/
        /** 选中按钮*/
        UIButton * PaybycardButton = [[UIButton alloc] initWithFrame:CGRectMake(WeChatButton.x, CGRectGetMaxY(WeChatButton.frame) + 40 * px, WeChatButton.width, WeChatButton.height)];
        [PaybycardButton  setImage:[UIImage imageNamed:@"筛选-未选中"] forState:UIControlStateNormal];
        [PaybycardButton  setImage:[UIImage imageNamed:@"勾"] forState:UIControlStateSelected];
        [PaybycardButton  addTarget:self action:@selector(WeChatButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [MethodView  addSubview:PaybycardButton];
        
        
        /** 微信标题*/
        UILabel * PaybycardTitle = [[UILabel alloc] initWithFrame:CGRectMake(WeChatTitle.x, PaybycardButton.y, WeChatTitle.width, WeChatButton.height)];
        PaybycardTitle.textColor = WeChatTitle.textColor;
        PaybycardTitle.text = @"刷卡";
        PaybycardTitle.textAlignment = WeChatTitle.textAlignment;
        PaybycardTitle.font = WeChatTitle.font;
        [MethodView addSubview:PaybycardTitle];
        
        
        UITextField * PaybycardTextField = [[UITextField alloc] init];
        PaybycardTextField.frame = CGRectMake(WeChatTextField.x, PaybycardTitle.y, WeChatTextField.width, WeChatTextField.height);
        //        WeChatTextField.placeholder = @"请输入手机号";
        [PaybycardTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [PaybycardTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        PaybycardTextField.keyboardType = UIKeyboardTypeNumberPad;
        PaybycardTextField.textColor = [UIColor blackColor];
        [MethodView addSubview:PaybycardTextField];
        self.PaybycardTextField = PaybycardTextField;
        
        
        UIView * PaybycardLine = [[UIView alloc] initWithFrame:CGRectMake(PaybycardTextField.x, CGRectGetMaxY(PaybycardTextField.frame), PaybycardTextField.width, WeChatLine.height)];
        PaybycardLine.backgroundColor = DividinglineColor;
        [MethodView addSubview:PaybycardLine];
        
        
        /** 微信标题*/
        UILabel * PaybycardYLabel = [[UILabel alloc] initWithFrame:CGRectMake(WeChatYLabel.x, PaybycardButton.y, WeChatYLabel.width, WeChatButton.height)];
        PaybycardYLabel.textColor = WeChatTitle.textColor;
        PaybycardYLabel.text = WeChatYLabel.text;
        PaybycardYLabel.textAlignment = WeChatTitle.textAlignment;
        PaybycardYLabel.font = WeChatTitle.font;
        [MethodView addSubview:PaybycardYLabel];
        
        
        
        
        /****************会员卡支付 Membershipcard**************/
        /** 选中按钮*/
        UIButton * MembershipcardButton = [[UIButton alloc] initWithFrame:CGRectMake(WeChatButton.x, CGRectGetMaxY(PaybycardButton.frame) + 40 * px, WeChatButton.width, WeChatButton.height)];
        [MembershipcardButton  setImage:[UIImage imageNamed:@"筛选-未选中"] forState:UIControlStateNormal];
        [MembershipcardButton  setImage:[UIImage imageNamed:@"勾"] forState:UIControlStateSelected];
        [MembershipcardButton  addTarget:self action:@selector(WeChatButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [MethodView  addSubview:MembershipcardButton];
        
        
        /** 微信标题*/
        UILabel * MembershipcardTitle = [[UILabel alloc] initWithFrame:CGRectMake(WeChatTitle.x, MembershipcardButton.y, 230 * px, WeChatButton.height)];
        MembershipcardTitle.textColor = WeChatTitle.textColor;
        MembershipcardTitle.text = @"会员卡支付";
        MembershipcardTitle.textAlignment = WeChatTitle.textAlignment;
        MembershipcardTitle.font = WeChatTitle.font;
        [MethodView addSubview:MembershipcardTitle];
        
        
        UITextField * MembershipcardTextField = [[UITextField alloc] init];
        MembershipcardTextField.frame = CGRectMake(CGRectGetMaxX(MembershipcardTitle.frame) + 20 * px, MembershipcardTitle.y, MethodView.width - WeChatButton.width - MembershipcardTitle.width - 120 * px, WeChatTextField.height);
        //        WeChatTextField.placeholder = @"请输入手机号";
        [MembershipcardTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [MembershipcardTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        MembershipcardTextField.keyboardType = UIKeyboardTypeNumberPad;
        MembershipcardTextField.textColor = [UIColor blackColor];
        [MethodView addSubview:MembershipcardTextField];
        self.MembershipcardTextField = MembershipcardTextField;
        
        
        UIView * MembershipcardLine = [[UIView alloc] initWithFrame:CGRectMake(MembershipcardTextField.x, CGRectGetMaxY(MembershipcardTitle.frame), MembershipcardTextField.width, WeChatLine.height)];
        MembershipcardLine.backgroundColor = DividinglineColor;
        [MethodView addSubview:MembershipcardLine];
        
        
        /** 微信标题*/
        UILabel * MembershipcardYLabel = [[UILabel alloc] initWithFrame:CGRectMake(WeChatYLabel.x, MembershipcardButton.y, WeChatYLabel.width, WeChatButton.height)];
        MembershipcardYLabel.textColor = WeChatTitle.textColor;
        MembershipcardYLabel.text = WeChatYLabel.text;
        MembershipcardYLabel.textAlignment = WeChatTitle.textAlignment;
        MembershipcardYLabel.font = WeChatTitle.font;
        [MethodView addSubview:MembershipcardYLabel];
        
        
        
        
        /****************支付宝 Membershipcard**************/
        /** 选中按钮*/
        UIButton * AlipayButton = [[UIButton alloc] initWithFrame:CGRectMake(WeChatButton.x, CGRectGetMaxY(MembershipcardButton.frame) + 40 * px, WeChatButton.width, WeChatButton.height)];
        [AlipayButton  setImage:[UIImage imageNamed:@"筛选-未选中"] forState:UIControlStateNormal];
        [AlipayButton  setImage:[UIImage imageNamed:@"勾"] forState:UIControlStateSelected];
        [AlipayButton  addTarget:self action:@selector(WeChatButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [MethodView  addSubview:AlipayButton];
        
        
        /** 微信标题*/
        UILabel * AlipayTitle = [[UILabel alloc] initWithFrame:CGRectMake(WeChatTitle.x, AlipayButton.y, 130 * px, WeChatButton.height)];
        AlipayTitle.textColor = WeChatTitle.textColor;
        AlipayTitle.text = @"支付宝";
        AlipayTitle.textAlignment = WeChatTitle.textAlignment;
        AlipayTitle.font = WeChatTitle.font;
        [MethodView addSubview:AlipayTitle];
        
        
        UITextField * AlipayTitleTextField = [[UITextField alloc] init];
        AlipayTitleTextField.frame = CGRectMake(CGRectGetMaxX(AlipayTitle.frame) + 20 * px, AlipayTitle.y, MethodView.width - WeChatButton.width - AlipayTitle.width - 120 * px, WeChatTextField.height);
        //        WeChatTextField.placeholder = @"请输入手机号";
        [AlipayTitleTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [AlipayTitleTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        AlipayTitleTextField.keyboardType = UIKeyboardTypeNumberPad;
        AlipayTitleTextField.textColor = [UIColor blackColor];
        [MethodView addSubview:AlipayTitleTextField];
        self.AlipayTitleTextField = AlipayTitleTextField;
        
        
        UIView * AlipayLine = [[UIView alloc] initWithFrame:CGRectMake(AlipayTitleTextField.x, CGRectGetMaxY(AlipayTitle.frame), AlipayTitleTextField.width, WeChatLine.height)];
        AlipayLine.backgroundColor = DividinglineColor;
        [MethodView addSubview:AlipayLine];
        
        
        /** 微信标题*/
        UILabel * AlipayYLabel = [[UILabel alloc] initWithFrame:CGRectMake(WeChatYLabel.x, AlipayButton.y, WeChatYLabel.width, WeChatButton.height)];
        AlipayYLabel.textColor = WeChatTitle.textColor;
        AlipayYLabel.text = WeChatYLabel.text;
        AlipayYLabel.textAlignment = WeChatTitle.textAlignment;
        AlipayYLabel.font = WeChatTitle.font;
        [MethodView addSubview:AlipayYLabel];
        
        
        
        
        /****************现金Cash**************/
        /** 选中按钮*/
        UIButton * CashButton = [[UIButton alloc] initWithFrame:CGRectMake(WeChatButton.x, CGRectGetMaxY(AlipayButton.frame) + 40 * px, WeChatButton.width, WeChatButton.height)];
        [CashButton  setImage:[UIImage imageNamed:@"筛选-未选中"] forState:UIControlStateNormal];
        [CashButton  setImage:[UIImage imageNamed:@"勾"] forState:UIControlStateSelected];
        [CashButton  addTarget:self action:@selector(WeChatButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [MethodView  addSubview:CashButton];
        
        
        /** 微信标题*/
        UILabel * CashTitle = [[UILabel alloc] initWithFrame:CGRectMake(WeChatTitle.x, CashButton.y, WeChatTitle.width, WeChatButton.height)];
        CashTitle.textColor = WeChatTitle.textColor;
        CashTitle.text = @"现金";
        CashTitle.textAlignment = WeChatTitle.textAlignment;
        CashTitle.font = WeChatTitle.font;
        [MethodView addSubview:CashTitle];
        
        
        UITextField * CashTextField = [[UITextField alloc] init];
        CashTextField.frame = CGRectMake(WeChatTextField.x, CashTitle.y, WeChatTextField.width, WeChatTextField.height);
        //        WeChatTextField.placeholder = @"请输入手机号";
        [CashTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [CashTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        CashTextField.keyboardType = UIKeyboardTypeNumberPad;
        CashTextField.textColor = [UIColor blackColor];
        [MethodView addSubview:CashTextField];
        self.CashTextField = CashTextField;
        
        
        UIView * CashLine = [[UIView alloc] initWithFrame:CGRectMake(PaybycardTextField.x, CGRectGetMaxY(CashTextField.frame), WeChatTextField.width, WeChatLine.height)];
        CashLine.backgroundColor = DividinglineColor;
        [MethodView addSubview:CashLine];
        
        
        /** 微信标题*/
        UILabel * CashYLabel = [[UILabel alloc] initWithFrame:CGRectMake(WeChatYLabel.x, CashButton.y, WeChatYLabel.width, WeChatButton.height)];
        CashYLabel.textColor = WeChatTitle.textColor;
        CashYLabel.text = WeChatYLabel.text;
        CashYLabel.textAlignment = WeChatTitle.textAlignment;
        CashYLabel.font = WeChatTitle.font;
        [MethodView addSubview:CashYLabel];
        
    
        /** 确定按钮*/
        UIButton * DetermineButton = [UIButton buttonWithType:UIButtonTypeCustom];
        DetermineButton.frame = CGRectMake(0, CGRectGetMaxY(MethodView.frame), ScreenWidth, 200 * px);
        [DetermineButton setTitle:@"确认" forState:UIControlStateNormal];
        [DetermineButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [DetermineButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
        DetermineButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(34 / 2)];
        [DetermineButton addTarget:self action:@selector(DetermineButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [showView  addSubview:DetermineButton];
}
- (void)tapAction:(id)tap{
    
    [self.backView removeFromSuperview];
}
//确认
- (void)DetermineButtonClick{
    
    WYCLogFunc;
    /***************** 剔除空格************/
    NSString *WeChatStr = [self.WeChatTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *MembershipcardStr = [self.MembershipcardTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *AlipayTitleStr = [self.AlipayTitleTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *PaybycardStr= [self.PaybycardTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *Cashtr= [self.CashTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    int summer = [WeChatStr intValue] + [MembershipcardStr intValue] + [AlipayTitleStr intValue] + [PaybycardStr intValue] + [Cashtr intValue];
    if (summer != [self.RoomMoney intValue]) {
        [MBManager showBriefAlert:@"输入金额不正确"];
        return;
    }
    NSDictionary *params = @{@"openid":self.Roomopenid,@"weChatPay":WeChatStr,@"membershipPay":MembershipcardStr,@"aliPay":AlipayTitleStr,@"bankCardPay":PaybycardStr,@"cashPay":Cashtr};
    
    [HTTPRequest POST:MSupdateRoomRecord params:params succeed:^(id responseObject) {
      
        if (CodeStr) {
            [self.backView removeFromSuperview];
            [MBManager showBriefAlert:responseObject[@"msg"]];
            [self ReloadData];
        }else{
            [self.backView removeFromSuperview];
            [MBManager showBriefAlert:responseObject[@"msg"]];
        }
    } failure:^(NSError *error) {
        
        [MBManager showBriefAlert:Failed];
    }];
    
    
}

- (void)BackButtonClick{
    WYCLogFunc;
    [self.backView removeFromSuperview];
}

- (void)WeChatButtonClick:(UIButton *)sender{
    
    sender.selected = !sender.selected;
}

@end
